package modules.majiang.data
{
	import modules.majiang.view.BonusPotViewProxy;
	
	import protobuf.BET_POOL;
	import protobuf.MSPKG_BET_POOL_NTF;
	
	public class BonusPotsData
	{
		private var tableDataModel:TableDataModel;
		
		public function BonusPotsData(tableDataModel:TableDataModel)
		{
			this.tableDataModel = tableDataModel;
		}
		
		/**
		 * 奖池数据
		 **/
		private var betPools:Array = [];
		
		public function set betPoolNtf(value:MSPKG_BET_POOL_NTF):void
		{
			betPools = (value == null ? null : value.betPool);
			
		}
		
		private var _potList:Array;
		
		public function set potList(value:Array):void
		{
			_potList = value;
			
			updateView();
		}
		
		public function get totalMoney():Number
		{
			var money:Number = 0;
			if (betPools)
			{
				for (var i:int = 0; i < betPools.length; i++)
				{
					var betPool:BET_POOL = betPools[i];
					money += betPool.money;
				}
			}
			return money;
		}
		
		public function updateView():void
		{
			if (_potList == null)
			{
				return;
			}
			
			//根据奖池数据列表显示奖池
			for (var i:int = 0; i < _potList.length; i++)
			{
				var bonusCanvasUI:BonusPotViewProxy = _potList[i];
				
				if (betPools != null && betPools[i] != null && tableDataModel.matchState == MatchState.INGAME)
				{
					var betPool:BET_POOL = betPools[i];
					//去除弃牌的玩家(校对服务器发过来的数据)
					var chairNum:int = betPool.chairList.length;
					while (chairNum > 0)
					{
						var isFold:Boolean = tableDataModel.isFold(betPool.chairList[chairNum - 1]);
						if (isFold)
						{
							betPool.chairList.splice(chairNum - 1, 1);
						}
						chairNum--;
					}
					
					bonusCanvasUI.updateView(betPool);
					bonusCanvasUI.setVisible(true);
				}
				else
				{
					bonusCanvasUI.setVisible(false);
				}
			}
		}
	}
}
